#include "stdafx.h"

namespace classifier_test
{

string attribute_type_to_str(const attribute_type& Type)
{
	if (Type == cont_attr) return "continuous";
	return "discrete";
}

attribute_type str_to_attribute_type(const string& S)
{
	if (S == "continuous") return cont_attr;
	if (S == "discrete") return discr_attr;
	throw runtime_error("Unknown attribute type");
}

void serialize(serializer& Serializer, attribute_type& Val)
{
	if (Serializer.is_loading())
		Val = str_to_attribute_type(Serializer[""].get<string>());
	else
		Serializer[""].put(attribute_type_to_str(Val));
}

void cont_domain::serialize(serializer& Serializer)
{
	Serializer
		("lower_bound", lower_bound)
		("upper_bound", upper_bound);
}

void discr_domain::serialize(serializer& Serializer)
{
	Serializer("count", count);
}

void attribute_domain::serialize(serializer& Serializer)
{
	Serializer("type", type);
	if (type == cont_attr) Serializer("cont", cont);
	if (type == discr_attr) Serializer("discr", discr);
}

bool record_domain::valid(const record& Val) const
{
	if (Val.size() != size()) return false;
	for (int I = 0; I != size(); I++) if (!(*this)[I].valid(Val[I])) return false;
	return true;
}

void record_domain::serialize(serializer& Serializer)
{
	cpputils::serialize(Serializer, (array<attribute_domain>&)*this);
}

}
